import request from '@/utils/request'

// 获取树状机构信息
export function getTreeList() {
  return request({
    url: '/manager/business-hall/tree'
  })
}
// 树形数据转换
export function keyNameWithLabelInArray(jsonArray) {
  const modifiedArray = []

  for (let i = 0; i < jsonArray.length; i++) {
    const data = jsonArray[i]

    traverse(data)
    modifiedArray.push(data)
  }
  return modifiedArray
}

function traverse(obj) {
  for (const key in obj) {
    if (typeof obj[key] === 'object') {
      // If the property value is an object, recursively traverse it
      traverse(obj[key])
    } else {
      if (key === 'name') {
        // Replace the "name" key with "label"
        obj['label'] = obj[key]
        delete obj[key]
      }
    }
  }
}
